/**
 * Ingenius-Group S.A.S
 *
 * Project: SAU
 * File: Response.java
 * Date: 13/11/2010
 */

package com.ingenius.sau.shared.model.instruments;

import java.util.Date;
import java.util.List;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.ingenius.sau.shared.model.core.BaseBean;

/**
 * Class <strong>Response</strong>
 * 
 * @author Jesus David
 * @version 0.1
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Response implements BaseBean {

	// DATA
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;

	@Persistent
	private Date createdDate;

	@Persistent
	private String assignedInstrumentId;

	@Persistent
	private String answer;

	@Persistent
	private List<String> responseOptionsIds;

	// CONSTRUCTORS

	public Response() {
	}

	public Response(String id) {
		this.id = id;
	}

	// METHODS

	public String getId() {
		return id;
	}

	public Date getCreatedDate() {
		return createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		this.createdDate = createdDate;
	}

	public String getAssignedInstrumentId() {
		return assignedInstrumentId;
	}

	public void setAssignedInstrumentId(String assignedInstrumentId) {
		this.assignedInstrumentId = assignedInstrumentId;
	}

	public List<String> getResponseOptionsIds() {
		return responseOptionsIds;
	}

	public void setResponseOptionsIds(List<String> responseOptionsIds) {
		this.responseOptionsIds = responseOptionsIds;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Response) {
			return ((Response) obj).getId().equals(id);
		}
		return false;
	}

	@Override
	public String toString() {
		return answer + " - " + createdDate;
	}

	public Response toDTO() {
		if (this != null) {
			this.setResponseOptionsIds(null);
		}
		return this;
	}
}
